﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;


namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OJobEdit : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get { return "OJobList"; }
        }

        #region
        /// <summary>
        /// 需要修改的用户ID
        /// </summary>
        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber","");
            }
        }

        private OJobInfo _obj;
        protected OJobInfo obj
        {
            get
            {
                if (_obj == null)
                    _obj = OJobController.GetBySerialNumber(SerialNumber);
                return _obj;
                //OMenuController.ge
            }
        }
        protected string GetDateFormat(string date)
        {
            if (string.IsNullOrEmpty(date))
                return "";
            DateTime dt = Convert.ToDateTime(date);
            return dt.ToString("yyyy-MM-dd"); ;
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "editjob")
            {
                addmenu();
                
            }
        }

        protected void addmenu()
        {
            OJobInfo obj2 = Request.SerializableObject<OJobInfo>();
            //2015-03-02 加入防呆处理
            string alertMsg = "";
            if (obj2.GPSIsSetUp && string.IsNullOrEmpty(obj2.GPSNumber))
            {
                alertMsg += "有安装GPS,但GPS号码未填写.<br/>";
            }
            if (obj2.GPSOutStorage && obj2.GPSStock)
            {
                alertMsg += "GPS出库及GPS库存不能同时勾选.<br/>";
            }
            if (!string.IsNullOrEmpty(obj2.InStorageDate) && string.IsNullOrEmpty(obj2.DownlineDate))
            {
                alertMsg += "请填写下线日期.<br/>";
            }
            if (!string.IsNullOrEmpty(obj2.OnlineDate) && string.IsNullOrEmpty(obj2.InStorageDate))
            {
                alertMsg += "请填写整机入库日期.<br/>";
            }
            if (!string.IsNullOrEmpty(alertMsg))
            { 
                AlertJson(alertMsg);       
            }

            //if (OUserController.CheckUserName(obj.UserName))
            //{
            //    AlertJson("登陆帐户名已存在,请重新输入.");
            //    return;
            //}

            this.AddLog(Permission.修改, obj, obj2);

            if (OJobController.Update(obj2))
                SuccessJson("修改成功","");
            else
                ErrorJson("修改失败","");
        }
    }
}